#include "SupplyManager.h"

#include "BuildOrderManager.h"
#include "TaskScheduler.h"
#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		SupplyManager::SupplyManager(BWSAL::SupplyManager* manager)
		{
			instance = manager;
		}

		SupplyManager::~SupplyManager()
		{
			BWSAL::SupplyManager::destroy();
		}
		
		SupplyManager::!SupplyManager()
		{
			BWSAL::SupplyManager::destroy();
		}

		void SupplyManager::Create(IBuildOrderManager^ buildOrderManager, ITaskScheduler^ taskScheduler)
		{
			BuildOrderManager^ manager = DirectCast<BuildOrderManager^>(buildOrderManager);
			TaskScheduler^ scheduler = DirectCast<TaskScheduler^>(taskScheduler);
			BWSAL::SupplyManager::destroy();
			s_instance = gcnew SupplyManager(BWSAL::SupplyManager::create(manager->instance, scheduler->instance));
		}

		SupplyManager^ SupplyManager::Instance::get()
		{
			return s_instance;
		}

		void SupplyManager::OnFrame()
		{
			instance->onFrame();
		}
	}
}
